#include "include/bt4.h"

bt4::bt4(void)
{
}
//----------------------------------------------------------------------------------
bt4::~bt4(void)
{
}
//----------------------------------------------------------------------------------
void bt4::createScene(void)
{
        mSceneMgr->setAmbientLight(Ogre::ColourValue(0.25, 0.25, 0.25));
        Ogre::Entity* ninjaEntity = mSceneMgr->createEntity("Ninja", "ninja.mesh");
        Ogre::SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("NinjaNode");
        node->attachObject(ninjaEntity);

        Ogre::Light* pointLight = mSceneMgr->createLight("pointLight");
        pointLight->setType(Ogre::Light::LT_POINT);
        pointLight->setPosition(Ogre::Vector3(250, 150, 250));
        pointLight->setDiffuseColour(Ogre::ColourValue::White);
        pointLight->setSpecularColour(Ogre::ColourValue::White);
}
//----------------------------------------------------------------------------------
bool bt4::processUnbufferedInput(const Ogre::FrameEvent& evt)
{
    static bool mMouseDown = false; // If a mouse button is depressed
    static Ogre::Real mToggle = 0.0; // The time left until next toggle
    static Ogre::Real mRotate = 0.13; // The rotate constant
    static Ogre::Real mMove = 250; // The movement constant
    bool currMouse = mMouse->getMouseState().buttonDown(OIS::MB_Left);
    if (currMouse && !mMouseDown)
    {
        Ogre::Light* light = mSceneMgr->getLight("pointLight");
        light->setVisible(!light->isVisible());
    }
    mMouseDown = currMouse;

    Ogre::Vector3 transVector = Ogre::Vector3::ZERO;
    if (mKeyboard->isKeyDown( OIS::KC_I )) //forward
    {
        transVector.z -= mMove;
    }
    if (mKeyboard->isKeyDown( OIS::KC_K )) //forward
    {
        transVector.z += mMove;
    }
    if (mKeyboard->isKeyDown( OIS::KC_J)) // Left - Yaw or strafe
    {
        if (mKeyboard->isKeyDown( OIS::KC_LSHIFT ))
        {
            mSceneMgr->getSceneNode("NinjaNode")->yaw(Ogre::Degree(mRotate * 5)); //yaw left
        }
        else 
        {
            transVector.x -= mMove; // strafe left
        }
    }
    if (mKeyboard->isKeyDown( OIS::KC_L)) // Right - Yaw or strafe
    {
        if (mKeyboard->isKeyDown( OIS::KC_LSHIFT ))
        {
            mSceneMgr->getSceneNode("NinjaNode")->yaw(Ogre::Degree(-mRotate * 5)); //yaw right 
        }
        else 
        {
            transVector.x += mMove; // strafe right
        }
    }
    if (mKeyboard->isKeyDown(OIS::KC_U)) //up
    {
        transVector.y += mMove;
    }
    if (mKeyboard->isKeyDown(OIS::KC_O)) //down
    {
        transVector.y -= mMove;
    }
    mSceneMgr->getSceneNode("NinjaNode")->translate(mSceneMgr->getSceneNode("NinjaNode")
->getOrientation() * transVector * evt.timeSinceLastFrame, Ogre::Node::TS_WORLD);
    return true;
}
//----------------------------------------------------------------------------------
bool bt4::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
    bool ret = Base::frameRenderingQueued(evt);
    if (!processUnbufferedInput(evt)) return false;
    return ret;
}
//----------------------------------------------------------------------------------
